package com.yst.gateway.monitor.controllers;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yst.gateway.monitor.common.beans.Response;
import com.yst.gateway.monitor.services.QzDictionaryService;
import com.yst.gateway.monitor.services.QzInterfaceService;
import com.yst.gateway.monitor.services.QzQueryService;

/**
 * 接口查询
 * @author dingjijun
 *
 */
@RestController
@RequestMapping(value = "/qz/query")
public class QzQueryController {
	
	@Autowired
	private QzQueryService qzQueryService;
	@Autowired
	private QzInterfaceService qzInterfaceService;
	
	@Autowired
	private QzDictionaryService qzDictionaryService;

//	@RequestMapping(value = "/listChan", method = RequestMethod.POST)
//	public Response post(@RequestBody @Validated({Default.class,Groups.Query.class}) ReqQueryInterface reqParam){
//		Response response=new Response();
//		
//		response.success(qzQueryService.queryInterface(reqParam));
//		return response;
//	}
	
	@RequestMapping(value = "/getByPage", method = RequestMethod.POST)
	public Response getByPage(@RequestBody Map<String, Object> paramMap) {
		Response response=new Response();
		int pageNum=1;
		int pageSize=10;
		try{
			if(paramMap.containsKey("pageNum")){
				pageNum=(Integer) paramMap.get("pageNum");
				paramMap.remove("pageNum");
			}
			if(paramMap.containsKey("pageSize")){
				pageSize=(Integer) paramMap.get("pageSize");
				paramMap.remove("pageSize");
			}
		}catch (Exception e) {
		}
		response.success(qzQueryService.getInterfaceByPage(pageNum, pageSize, paramMap));
		return response;
	}
	
	@RequestMapping(value = "/getInterAddrs/{id}", method = RequestMethod.GET)
	public Response getInterAddrs(@PathVariable("id") String id) {
		
		Response response=new Response();
		if(id!=null){
			response.success(qzInterfaceService.getDeployInfo(id));
		}		
		return response;
	}
	
	@RequestMapping(value = "/getInterProps/{id}", method = RequestMethod.GET)
	public Response getInterProps(@PathVariable("id") String id) {
		
		Response response=new Response();
		if(id!=null){
			response.success(qzQueryService.getInterProps(id));
		}		
		return response;
	}
}